package com.example.aop.config;

import com.example.aop.annotation.LogASP;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2020/9/5 19:23
 */
@Aspect
@Component
public class LogAop
{
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    @Around("@annotation(logASP)")
    public Object around(ProceedingJoinPoint joinPoint, LogASP logASP) throws Throwable
    {
        long a = System.currentTimeMillis();
        System.out.println("方法开始时间是:"+a);
        Object o = joinPoint.proceed();
        long b = System.currentTimeMillis();
        System.out.println("方法结束时间是:"+b) ;
        log.info("方法总耗时{}秒",b-a);
        return o;
    }
}
